﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using iLangl.Model;
using iLangl.Customer.Actions;
using iLangl.Transport;
using iLangl.Transport.Communication;
using iLangl.Model.Rules;
using System.IO;
using iLangl.StateMachine;
using iLangl.Plugin.ConfigFileSettings;

namespace iLangl.Tests.CustomerActions
{
	[TestClass]
	public class OrderProjectTest : ProjectValidationTest
	{
		[TestMethod]
		public void OrderProject()
		{
			SwitchToCustomerSide();

			RegisterNewProjectAction registerNewProject = new RegisterNewProjectAction(GetProject());
			registerNewProject.Send();
		}

		[TestMethod]
		[ExpectedException(typeof(ApplicationException))]
		public void OrderProjectWithInvalidCredential()
		{
			SwitchToCustomerSide();

			string originalAccount = PluginConfiguration.Instance.AccountPassword;
			PluginConfiguration.Instance.SetAccountPassword("Phake");

			RegisterNewProjectAction registerNewProject = new RegisterNewProjectAction(GetProject());
			registerNewProject.Execute();
			//Restore Original Password
			PluginConfiguration.Instance.SetAccountPassword(originalAccount);
		}

		[TestMethod]
		public void ValidateProject()
		{
			ValidateProject vproject = new ValidateProject();
			IList<IError> errors = vproject.Validate(GetProject());

			Assert.AreEqual(errors.Count, 2);
		}

		
	}
} 
